package xuliehualiu;

import java.io.*;
import java.util.ArrayList;

public class duogeObj {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        read();
//        save();
    }

    private static void save() throws IOException {
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("D:\\study\\999.java拓展\\自己敲代码-git\\javaBase\\homeExtendDay14\\src\\main\\java\\xuliehualiu\\duoge.txt"));
        Student tkf = new Student("tkf", 1);
        Student tkf2 = new Student("tkf2", 1);
        Student tkf3 = new Student("tkf3", 1);
        ArrayList<Student> al =  new ArrayList<>();
        al.add(tkf);
        al.add(tkf2);
        al.add(tkf3);
        oos.writeObject(al);
    }

    private static void read() throws IOException, ClassNotFoundException {
        ObjectInputStream ois =   new ObjectInputStream(new FileInputStream("D:\\study\\999.java拓展\\自己敲代码-git\\javaBase\\homeExtendDay14\\src\\main\\java\\xuliehualiu\\duoge.txt"));
        ArrayList<Student> o = (ArrayList<Student>)ois.readObject();
        o.forEach(item-> System.out.println(item));
    }
}
